package com.xinqi.modules.exam.common.enums;

import com.xinqi.modules.exam.common.constants.ExamConstants;

import java.util.function.Supplier;

import static com.xinqi.common.base.error.CommonErrors.BAD_REQUEST;

/**
 * 测评限制处理枚举
 *
 * @author linkai
 * @date 2023/7/6
 */
public enum ExamLimitEnum {
    答题时间上限(ExamConstants.Limit.ANSWER_TIME_LIMIT, "答题时间已超过上限"),
    试卷题目上限(ExamConstants.Limit.EXAM_QUESTION_NUM_LIMIT, "测评卷题目已超上限"),
    ;

    private final long limitNum;
    private final String error;

    ExamLimitEnum(long limitNum, String error) {
        this.limitNum = limitNum;
        this.error = error;
    }

    public void check(long num) {
        BAD_REQUEST.check(validate(num), error);
    }

    public void check(Supplier<Integer> s) {
        BAD_REQUEST.check(validate(s.get()), error);
    }

    public void check(int num, String error) {
        BAD_REQUEST.check(validate(num), error);
    }

    public boolean validate(long num) {
        return num <= limitNum;
    }
}
